package com.javarush.test.level08.lesson11.home06;

/* Вся семья в сборе
1. Создай класс Human с полями имя (String), пол (boolean), возраст (int), дети (ArrayList<Human>).
2. Создай объекты и заполни их так, чтобы получилось: два дедушки, две бабушки, отец, мать, трое детей.
3. Вывести все объекты Human на экран.
*/

import java.util.ArrayList;
import java.util.Collections;

public class Solution
{
    public static void main(String[] args)
    {
        //Написать тут ваш код
        Human child1 = new Human("Child1", true, 5, new ArrayList<Human>());
        Human child2 = new Human("Child2", false, 10, new ArrayList<Human>());
        Human child3 = new Human("Child3", true, 15, new ArrayList<Human>());

        ArrayList<Human> children = new ArrayList<Human>();
        Collections.addAll(children, child1, child2, child3);


        Human father = new Human("Father", true, 30, children);
        Human mother = new Human("Mother", false, 35, children);

        ArrayList<Human> childFather = new ArrayList<Human>();
        childFather.add(father);

        ArrayList<Human> childMother = new ArrayList<Human>();
        childMother.add(mother);

        Human grandFather1 = new Human("GrandFather1", true, 50, childFather);
        Human grandMother1 = new Human("GrandMother1", false, 55, childFather);

        Human grandFather2 = new Human("GrandFather2", true, 60, childMother);
        Human grandMother2 = new Human("GrandMother2", false, 65, childMother);

        System.out.println(grandFather1);
        System.out.println(grandFather2);
        System.out.println(grandMother1);
        System.out.println(grandMother2);
        System.out.println(father);
        System.out.println(mother);
        System.out.println(child1);
        System.out.println(child2);
        System.out.println(child3);
    }

    public static class Human
    {
        //Написать тут ваш код
        public String name;
        public boolean sex;
        public int age;
        public ArrayList<Human> children;

        public Human(String name, boolean sex, int age, ArrayList<Human> children)
        {
            this.name = name;
            this.sex = sex;
            this.age = age;
            this.children = children;
        }

        public String toString()
        {
            String text = "";
            text += "Имя: " + this.name;
            text += ", пол: " + (this.sex ? "мужской" : "женский");
            text += ", возраст: " + this.age;


            int childCount = this.children.size();
            if (childCount > 0)
            {
                text += ", дети: "+this.children.get(0).name;

                for (int i = 1; i < childCount; i++)
                {
                    Human child = this.children.get(i);
                    text += ", "+child.name;
                }
            }

            return text;
        }
    }

}
